package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallConfigMapper;
import org.linlinjava.litemall.db.domain.LitemallConfig;
import org.linlinjava.litemall.db.domain.LitemallConfigExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallConfigService {
    @Resource
    private LitemallConfigMapper configMapper;

    public List<LitemallConfig> queryIndex() {
        LitemallConfigExample example = new LitemallConfigExample();
        example.or().andVisibledEqualTo(true);
        return configMapper.selectByExample(example);
    }

    public List<LitemallConfig> querySelective(Integer page, Integer limit, String sort, String order) {
        LitemallConfigExample example = new LitemallConfigExample();
        LitemallConfigExample.Criteria criteria = example.createCriteria();

        criteria.andVisibledEqualTo(true);

        PageHelper.startPage(page, limit);
        return configMapper.selectByExample(example);
    }

    public int countSelective(Integer page, Integer size, String sort, String order) {
        LitemallConfigExample example = new LitemallConfigExample();
        LitemallConfigExample.Criteria criteria = example.createCriteria();

        criteria.andVisibledEqualTo(true);
        return (int)configMapper.countByExample(example);
    }

    public void updateById(LitemallConfig config) {
        configMapper.updateByPrimaryKeySelective(config);
    }

    public void deleteById(Integer id) {
        configMapper.deleteByPrimaryKey(id);
    }

    public LitemallConfig findById(Integer id) {
        return configMapper.selectByPrimaryKey(id);
    }
}
